<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="车牌号" prop="licenseNum">
        <el-input
          v-model="queryParams.licenseNum"
          placeholder="请输入车牌号"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="车辆组" prop="venicleGroup">
        <el-input
          v-model="queryParams.venicleGroup"
          placeholder="请输入车辆组"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="在线" prop="onLine">
        <el-input
          v-model="queryParams.onLine"
          placeholder="请输入在线"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="GPS定位时间" prop="gps">
        <el-input
          v-model="queryParams.gps"
          placeholder="请输入GPS定位时间"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="车速" prop="speed">
        <el-input
          v-model="queryParams.speed"
          placeholder="请输入车速"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="日里程" prop="dailyMileage">
        <el-input
          v-model="queryParams.dailyMileage"
          placeholder="请输入日里程"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="月里程" prop="monthlyMileage">
        <el-input
          v-model="queryParams.monthlyMileage"
          placeholder="请输入月里程"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="累计里程" prop="amtMileage">
        <el-input
          v-model="queryParams.amtMileage"
          placeholder="请输入累计里程"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="位置" prop="position">
        <el-input
          v-model="queryParams.position"
          placeholder="请输入位置"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="SIM卡" prop="sim">
        <el-input
          v-model="queryParams.sim"
          placeholder="请输入SIM卡"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="颜色" prop="color">
        <el-input
          v-model="queryParams.color"
          placeholder="请输入颜色"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="脉冲速度" prop="pulseVelocity">
        <el-input
          v-model="queryParams.pulseVelocity"
          placeholder="请输入脉冲速度"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="方向" prop="direction">
        <el-input
          v-model="queryParams.direction"
          placeholder="请输入方向"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="油量" prop="oilQuantity">
        <el-input
          v-model="queryParams.oilQuantity"
          placeholder="请输入油量"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="海拔" prop="altitude">
        <el-input
          v-model="queryParams.altitude"
          placeholder="请输入海拔"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="经纬度" prop="lonLat">
        <el-input
          v-model="queryParams.lonLat"
          placeholder="请输入经纬度"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['system:sssj:add']"
        >新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['system:sssj:edit']"
        >修改</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['system:sssj:remove']"
        >删除</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['system:sssj:export']"
        >导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="sssjList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="id" align="center" prop="id" />
      <el-table-column label="车牌号" align="center" prop="licenseNum" />
      <el-table-column label="车辆组" align="center" prop="venicleGroup" />
      <el-table-column label="在线" align="center" prop="onLine" />
      <el-table-column label="GPS定位时间" align="center" prop="gps" />
      <el-table-column label="车速" align="center" prop="speed" />
      <el-table-column label="日里程" align="center" prop="dailyMileage" />
      <el-table-column label="月里程" align="center" prop="monthlyMileage" />
      <el-table-column label="累计里程" align="center" prop="amtMileage" />
      <el-table-column label="位置" align="center" prop="position" />
      <el-table-column label="状态" align="center" prop="status" />
      <el-table-column label="SIM卡" align="center" prop="sim" />
      <el-table-column label="颜色" align="center" prop="color" />
      <el-table-column label="脉冲速度" align="center" prop="pulseVelocity" />
      <el-table-column label="方向" align="center" prop="direction" />
      <el-table-column label="油量" align="center" prop="oilQuantity" />
      <el-table-column label="海拔" align="center" prop="altitude" />
      <el-table-column label="经纬度" align="center" prop="lonLat" />
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['system:sssj:edit']"
          >修改</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['system:sssj:remove']"
          >删除</el-button>
        </template>
      </el-table-column>
    </el-table>
    
    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改实时监控_实时数据对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-form-item label="车牌号" prop="licenseNum">
          <el-input v-model="form.licenseNum" placeholder="请输入车牌号" />
        </el-form-item>
        <el-form-item label="车辆组" prop="venicleGroup">
          <el-input v-model="form.venicleGroup" placeholder="请输入车辆组" />
        </el-form-item>
        <el-form-item label="在线" prop="onLine">
          <el-input v-model="form.onLine" placeholder="请输入在线" />
        </el-form-item>
        <el-form-item label="GPS定位时间" prop="gps">
          <el-input v-model="form.gps" placeholder="请输入GPS定位时间" />
        </el-form-item>
        <el-form-item label="车速" prop="speed">
          <el-input v-model="form.speed" placeholder="请输入车速" />
        </el-form-item>
        <el-form-item label="日里程" prop="dailyMileage">
          <el-input v-model="form.dailyMileage" placeholder="请输入日里程" />
        </el-form-item>
        <el-form-item label="月里程" prop="monthlyMileage">
          <el-input v-model="form.monthlyMileage" placeholder="请输入月里程" />
        </el-form-item>
        <el-form-item label="累计里程" prop="amtMileage">
          <el-input v-model="form.amtMileage" placeholder="请输入累计里程" />
        </el-form-item>
        <el-form-item label="位置" prop="position">
          <el-input v-model="form.position" placeholder="请输入位置" />
        </el-form-item>
        <el-form-item label="SIM卡" prop="sim">
          <el-input v-model="form.sim" placeholder="请输入SIM卡" />
        </el-form-item>
        <el-form-item label="颜色" prop="color">
          <el-input v-model="form.color" placeholder="请输入颜色" />
        </el-form-item>
        <el-form-item label="脉冲速度" prop="pulseVelocity">
          <el-input v-model="form.pulseVelocity" placeholder="请输入脉冲速度" />
        </el-form-item>
        <el-form-item label="方向" prop="direction">
          <el-input v-model="form.direction" placeholder="请输入方向" />
        </el-form-item>
        <el-form-item label="油量" prop="oilQuantity">
          <el-input v-model="form.oilQuantity" placeholder="请输入油量" />
        </el-form-item>
        <el-form-item label="海拔" prop="altitude">
          <el-input v-model="form.altitude" placeholder="请输入海拔" />
        </el-form-item>
        <el-form-item label="经纬度" prop="lonLat">
          <el-input v-model="form.lonLat" placeholder="请输入经纬度" />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { listSssj, getSssj, delSssj, addSssj, updateSssj } from "@/api/shis/sssj";

export default {
  name: "Sssj",
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 实时监控_实时数据表格数据
      sssjList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        licenseNum: null,
        venicleGroup: null,
        onLine: null,
        gps: null,
        speed: null,
        dailyMileage: null,
        monthlyMileage: null,
        amtMileage: null,
        position: null,
        status: null,
        sim: null,
        color: null,
        pulseVelocity: null,
        direction: null,
        oilQuantity: null,
        altitude: null,
        lonLat: null
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
      }
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询实时监控_实时数据列表 */
    getList() {
      this.loading = true;
      listSssj(this.queryParams).then(response => {
        this.sssjList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        licenseNum: null,
        venicleGroup: null,
        onLine: null,
        gps: null,
        speed: null,
        dailyMileage: null,
        monthlyMileage: null,
        amtMileage: null,
        position: null,
        status: null,
        sim: null,
        color: null,
        pulseVelocity: null,
        direction: null,
        oilQuantity: null,
        altitude: null,
        lonLat: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加实时监控_实时数据";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids
      getSssj(id).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改实时监控_实时数据";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.id != null) {
            updateSssj(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addSssj(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$modal.confirm('是否确认删除实时监控_实时数据编号为"' + ids + '"的数据项？').then(function() {
        return delSssj(ids);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('system/sssj/export', {
        ...this.queryParams
      }, `sssj_${new Date().getTime()}.xlsx`)
    }
  }
};
</script>
